<template>
	<view class="home-box left clearfix">
		<view class="home-mianbao-box left clearfix">
			我的订单
		</view>
		
		<view class="home-content left clearfix">
			<uni-table border stripe emptyText="暂无更多数据" >
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="center" width="70">ID</uni-th>
					<uni-th align="center" width="200">订单号</uni-th>
					<uni-th width="100" align="center">支付金额</uni-th>
					<uni-th width="100" align="center">魔豆</uni-th>
					<uni-th align="center">说明</uni-th>
					<uni-th align="center" width="200">支付时间</uni-th>
				</uni-tr>
				<!-- 表格数据行 -->
				<uni-tr v-for="(item,index) in data">
					<uni-td  align="center">{{index + 1}}</uni-td>
					<uni-td align="center">{{item.order_no||'--'}}</uni-td>
					<uni-td align="center">{{item.money}}</uni-td>
					<uni-td align="center">{{item.dou}}</uni-td>
					<uni-td align="center">{{item.text}}</uni-td>
					<uni-td align="center">
						<uni-dateformat :date="item.date" format="yyyy-MM-dd hh:mm"></uni-dateformat>

					</uni-td>
				</uni-tr>
				
			</uni-table>
		</view>
		<view class="order-page left clearfix">
			<uni-pagination :current="currentPage" @change="setCurrentPage" title="标题文字" :total="total"></uni-pagination>
		</view>
	</view>
</template>

<style scoped>
	.order-page{width:100%;height:50px;margin-top:20px;}
	body, uni-page-body{height:100%;}
	.home-content{width:96%;height:calc(100% - 150px);margin-left:2%;margin-top:30px;}
	.home-mianbao-box{width:calc(100% - 10px);padding-left:10px;height:30px;margin-top:15px;border-bottom:1px solid #eee;font-size:14px;}
	.home-box{width:100%;height:100%;}
</style>

<script>
	var db = uniCloud.database();
	export default {
		name:"order-list",
		data() {
			return {
				data:[],
				total:0,
				currentPage:1
			};
		},
		props:['userinfo'],
		mounted() {
			var that = this;
			setTimeout(function(){
				that.getDataList();
			},500);
		},
		methods:{
			//设置当前页码
			setCurrentPage(e){
				this.currentPage = e.current;
				this.getDataList(e.current);
			},
			getDataList(page = 1){
				uni.showLoading({
					title:'加载中'
				})
				var skip = (page - 1) * 10;
				var userinfo = this.userinfo;
				if(userinfo && userinfo._id){
					db.collection('recharge_log').where({uid:userinfo._id}).skip(skip).limit(10).get({getCount:true}).then(res=>{
						uni.hideLoading();
						this.data = res.result.data;
						this.total = res.result.count;
					})
				}
				
			}
		}
	}
</script>
